<template>
    <SchemaForm v-model="searchType" :columns="columns" @searchHandle="search" @handleReset="handleReset" />
</template>

<script lang="ts" setup>
import SchemaForm from '@/components/SchemaForm.vue'

export type SearchType = {
    id: string
    header: string
    taxIdentNo: string
    orderNo: string
    invoiceHeaderType: string
    date: string
}

const TypeList = reactive([
    {
        value: '',
        label: '全部',
    },
    {
        value: 'ENTERPRISE',
        label: '企业',
    },
    {
        value: 'PERSONAL',
        label: '个人',
    },
])

const searchType = reactive({
    id: '',
    header: '',
    taxIdentNo: '',
    orderNo: '',
    invoiceHeaderType: '',
    date: '',
})
const columns = [
    {
        label: '申请单号',
        prop: 'id',
        valueType: 'copy',
        fieldProps: {
            placeholder: '请输入申请单号',
        },
    },
    {
        label: '抬头',
        labelWidth: 40,
        prop: 'header',
        valueType: 'copy',
        fieldProps: {
            placeholder: '请输入抬头',
        },
    },
    {
        label: '申请税号',
        prop: 'taxIdentNo',
        valueType: 'copy',
        fieldProps: {
            placeholder: '请输入税号',
        },
    },
    {
        label: '关联订单号',
        labelWidth: 85,
        prop: 'orderNo',
        valueType: 'copy',
        fieldProps: {
            placeholder: '请输入关联订单号',
        },
    },
    {
        label: '抬头类型',
        prop: 'invoiceHeaderType',
        valueType: 'select',
        options: TypeList,
        fieldProps: {
            placeholder: '请选择',
        },
    },
    {
        label: '申请时间',
        prop: 'date',
        valueType: 'date-picker',
        fieldProps: {
            type: 'datetimerange',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期',
            format: 'YYYY/MM/DD HH:mm:ss',
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
        },
    },
]
const $emit = defineEmits(['onSearchParams'])

function search() {
    $emit('onSearchParams', toRaw(searchType))
}
const handleReset = () => {
    ;(Object.keys(searchType) as (keyof SearchType)[]).forEach((key) => (searchType[key] = ''))
    search()
}
</script>
